package com.wwg.warehouse.usecase

import com.wwg.warehouse.data.Content
import com.wwg.warehouse.data.DBEntity
import com.wwg.warehouse.entities.BBookmark
import com.wwg.warehouse.entities.WBookmark
import com.wwg.warehouse.usecase.access.IAccess.Companion.FOLDER
import com.wwg.warehouse.usecase.access.IAccess.Companion.URL

/**
 * 单纯转换，web bean 不能提供的信息后续修正
 */
fun WBookmark.toDb(): DBEntity {
    val content = Content(
        uid = "",
        url = url ?: "",
        isFolder = "folder" == type,
        date = date ?: System.currentTimeMillis().toString(),
        state = 0,
    )

    return DBEntity(
        name = name,
        path = path ?: "",
        parentName = "",
        parentPath = "",
        content = content,
        order = 0
    )
}

fun DBEntity.toBE(): BBookmark {
    return BBookmark(
        name = name,
        path = path,
        isFolder = content?.isFolder ?: content?.url?.isEmpty() ?: false,
        date = content?.date ?: "",
        url = content?.url ?: "",
        children = mutableListOf(),
        isSelected = false
    )
}